package com.collectionday03demo;

import java.util.ArrayList;
import java.util.Iterator;

public class GenericDemo {
    public static void main(String[] args) {

        ArrayList<String> arr = new ArrayList<>();
        arr.add("aaa");
        arr.add("bbb");
        arr.add("ccc");
        //集合指定范型后只能存放相应类型

        //迭代器范型应和集合范型保持一致
        Iterator<String> ite = arr.iterator();
        while (ite.hasNext()){
            String str  = ite.next();
            System.out.print(str + " ");
        }
        System.out.println();
        for (String ss : arr){
            System.out.print(ss + " ");
        }
        ArrayList<Point> arr2 = new ArrayList<>();
        arr2.add(new Point(1,2));
        arr2.add(new Point(3,4));
        arr2.add(new Point(5,6));


        Iterator<Point> it = arr2.iterator();
        while (it.hasNext()){
            Point p = it.next();
            System.out.println(p);
        }

        for (Point p : arr2){
            System.out.println(p);
        }


    }
}
